package com.mysiteforme.admin.util;

import java.util.HashMap;

/**
 * ResponseBody构造器。一般用于ajax、rest等类型的Web服务
 */
@SuppressWarnings("serial")
public class Ret extends HashMap<String, Object> {
    public static Ret success(){
        return success("成功");
    }
    public static Ret success(String message){
        Ret ret = new Ret();
        ret.setSuccess(true);
        ret.setMessage(message);
        return ret;
    }

    public static Ret failure(String message){
        Ret ret = new Ret();
        ret.setSuccess(false);
        ret.setMessage(message);
        return ret;
    }


    public Ret setSuccess(Boolean success) {
        if (success != null) put("success", success);
        return this;
    }

    public Ret setMessage(String message) {
        if (message != null) put("message", message);
        return this;
    }

    public Ret setData(Object data) {
        if (data != null) put("data", data);
        return this;
    }

    public Ret setPage(Integer page) {
        if (page != null) put("page", page);
        return this;
    }
    
    public Ret setCurrentPage(Integer currentPage){
    	if (currentPage != null) put("currentPage", currentPage);
        return this;
    }

    public Ret setLimit(Integer limit) {
        if (limit != null) put("limit", limit);
        return this;
    }

    public Ret setTotal(Long total) {
        if (total != null) put("total", total);
        return this;
    }

    public Ret setAny(String key, Object value) {
        if (key != null && value != null) put(key, value);
        return this;
    }
}
